//:C14:InheritStack2.cpp
// Composition vs. inheritance
#include "../require.h"
#include "../09/Stack4.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

class StringStack
{
    Stack stack;    // Embed instead of inherit
    public:
        void push(string *str)
        {
            stack.push(str);
        }

        string *peek() const
        {
            return (string*)stack.peek();
        }

        string *pop()
        {
            return (string*)stack.pop();
        }
};

int main(void)
{
    ifstream in("InheritStack2.cpp");
    assure(in, "InheritStack2.cpp");
    string line;
    StringStack textlines;

    while(getline(in, line))
    {
        textlines.push(new string(line));
    }
    string *s;
    while((s = textlines.pop()) != 0)    // No cast
    {
        cout << *s << endl;
    }
}